home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / gnu_st.lha / gnu_st / smalltalk-1.1.1 / ClassDescription.st < prev    next >
Text File  |  1991-09-12  |  7KB  |  279 lines

  1. "======================================================================
  2. |
  3. |   ClassDescription Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne     23 Sep 89      fileOutCategory: is dangerous, so I make it write to
  34. |              a subdirectory called './categories'.
  35. |
  36. | sbyrne     25 Apr 89      created.
  37. |
  38. "
  39.  
  40. Behavior subclass: #ClassDescription
  41.      instanceVariableNames: 'name comment instanceVariables category'
  42.      classVariableNames: ''
  43.      poolDictionaries: ''
  44.      category: nil.
  45.  
  46. ClassDescription comment: 
  47. 'My instances record information generally attributed to classes and
  48. metaclasses; namely, the class name, class comment (you wouldn''t be
  49. reading this if it weren''t for me), a list of the instance variables
  50. of the class, and the class category.  I provide methods that
  51. access classes by category, and allow whole categories of classes to be
  52. filed out to external disk files.' !
  53.  
  54.  
  55.  
  56. !ClassDescription methodsFor: 'accessing class description'!
  57.  
  58. name
  59.     ^name
  60. !
  61.  
  62. comment
  63.     ^comment
  64. !
  65.  
  66. comment: aString
  67.     comment _ aString
  68. !
  69.  
  70. addInstVarName: aString
  71.     instanceVariables _ instanceVariables copyWith: aString
  72. !
  73.  
  74. removeInstVarName: aString
  75.     instanceVariables _ instanceVariables copyWithout: aString
  76. !!
  77.  
  78.  
  79.  
  80. !ClassDescription methodsFor: 'organization of messages and classes'!
  81.  
  82. category
  83.     ^category
  84. !
  85.  
  86. category: aString
  87.     aString isNil
  88.     ifTrue: [ category _ nil ]
  89.     ifFalse: [ category _ aString asSymbol ]
  90. !
  91.  
  92. removeCategory: aString
  93.     | selector method category |
  94.     methodDictionary isNil
  95.         ifTrue: [ ^self ].
  96.     category _ aString asSymbol.
  97.     methodDictionary associationsDo:
  98.         [ :assoc | method _ assoc key.
  99.                method methodCategory = category
  100.                ifTrue: [ methodDictionary remove: assoc ] ].
  101. !
  102.  
  103. whichCategoryIncludesSelector: selector
  104.     | method |
  105.     methodDictionary isNil
  106.         ifTrue: [ ^nil ].
  107.     method _ methodDictionary at: selector.
  108.     ^method methodCategory
  109. !!
  110.  
  111.  
  112.  
  113. !ClassDescription methodsFor: 'copying'!
  114.  
  115. copy: selector from: aClass
  116.     | method |
  117.     method _ aClass compiledMethodAt: selector.
  118.     methodDictionary at: selector put: method.
  119. !
  120.  
  121. copy: selector from: aClass classified: categoryName
  122.     | method |
  123.     method _ (aClass compiledMethodAt: selector) deepCopy.
  124.     method methodCategory: categoryName.
  125.     methodDictionary at: selector put: method
  126. !
  127.  
  128. copyAll: arrayOfSelectors from: class
  129.     arrayOfSelectors do:
  130.     [ :selector | self copy: selector
  131.                from: class ]
  132. !
  133.  
  134. copyAll: arrayOfSelectors from: class classified: categoryName
  135.     arrayOfSelectors do:
  136.     [ :selector | self copy: selector
  137.                from: class
  138.                classified: categoryName ]
  139. !
  140.  
  141. copyAllCategoriesFrom: aClass
  142.     | method |
  143.     aClass selectors do:
  144.     [ :selector | self copy: selector from: aClass ]
  145. !
  146.  
  147. copyCategory: categoryName from: aClass
  148.     | method |
  149.     aClass selectors do:
  150.     [ :selector | method _ aClass compiledMethodAt: selector.
  151.               method methodCategory = categoryName
  152.               ifTrue: [ self copy: selector from: aClass ] ]
  153. !
  154.  
  155. copyCategory: categoryName from: aClass classified: newCategoryName
  156.     | method |
  157.     aClass selectors do:
  158.     [ :selector | method _ aClass compiledMethodAt: selector.
  159.               method methodCategory = categoryName
  160.               ifTrue: [ self copy: selector
  161.                      from: aClass
  162.                      classified: newCategoryName ] ]
  163. !!
  164.  
  165.  
  166.  
  167. !ClassDescription methodsFor: 'compiling'!
  168.  
  169. compile: code classified: categoryName
  170.     | method |
  171.     self notYetImplemented
  172. !
  173.  
  174. compile: code classified: categoryName notifying: requestor
  175.     self notYetImplemented
  176. !!
  177.  
  178.  
  179.  
  180. !ClassDescription methodsFor: 'accessing instances and variables'!
  181.  
  182. instVarNames
  183.     ^instanceVariables
  184. !!
  185.  
  186.  
  187.  
  188. !ClassDescription methodsFor: 'printing'!
  189.  
  190. classVariableString
  191.     self subclassResponsibility
  192. !
  193.  
  194. instanceVariableString
  195.     | aString |
  196.     instanceVariables isNil ifTrue: [ ^'' ].
  197.     aString _ String new: 0.
  198.     instanceVariables do: [ :instVarName | aString _ aString ,
  199.                                               instVarName , ' ' ].
  200.     ^aString
  201. !
  202.  
  203. sharedVariableString
  204.     self subclassResponsibility
  205. !!
  206.  
  207.  
  208.  
  209. !ClassDescription methodsFor: 'filing'!
  210.  
  211. fileOutOn: aFileStream
  212.     | categories now |
  213.     categories _ Set new.
  214.     methodDictionary isNil ifTrue: [ ^self ].
  215.     methodDictionary do:
  216.     [ :method | categories add: (method methodCategory) ].
  217.     '''Filed out from ' printOn: aFileStream.
  218.     Version printOn: aFileStream.
  219.     ' on ' printOn: aFileStream.
  220.     now _ Date dateAndTimeNow.
  221.     (now at: 1) printOn: aFileStream.
  222.     '  ' printOn: aFileStream.
  223.     (now at: 2) printOn: aFileStream.
  224.     ' GMT''!' printOn: aFileStream.    
  225.     Character nl printOn: aFileStream.
  226.     Character nl printOn: aFileStream.
  227.     categories asSortedCollection do:
  228.         [ :category | self emitCategory: category toStream: aFileStream ]
  229. !
  230.  
  231. fileOutCategory: categoryName
  232.     | aFileStream fileName |
  233.     name notNil
  234.         ifTrue: [ fileName _ name ]
  235.     ifFalse: [ fileName _ (self instanceClass name) , '-class' ].
  236.     fileName _ './categories/', fileName , '.st' .
  237.     aFileStream _ FileStream open: fileName mode: 'w'.
  238.     self emitCategory: categoryName toStream: aFileStream.
  239.     aFileStream close
  240. !!
  241.  
  242.  
  243.  
  244. !ClassDescription methodsFor: 'private'!
  245.  
  246. emitCategory: category toStream: aFileStream
  247.     "I write legal Smalltalk load syntax definitions of all of my methods
  248.      are in the 'category' category to the aFileStream"
  249.     '!' printOn: aFileStream.
  250.     self printOn: aFileStream.
  251.     ' methodsFor: ''' printOn: aFileStream.
  252.     category printOn: aFileStream.
  253.     '''!' printOn: aFileStream.
  254.     methodDictionary notNil
  255.       ifTrue: [ methodDictionary do:
  256.               [ :method | (method methodCategory) = category
  257.                       ifTrue: [ '
  258.  
  259. '                                printOn: aFileStream.
  260.                             method methodSourceString
  261.                                  printOn: aFileStream.
  262.                                 '!' printOn: aFileStream ] ] ].
  263.     '!
  264.  
  265. '   printOn: aFileStream
  266.  
  267. !
  268.  
  269. setName: aSymbol
  270.     name _ aSymbol
  271. !
  272.  
  273. setInstanceVariables: instVariableArray
  274.     instanceVariables _ instVariableArray
  275.  
  276. !!
  277.